package uva;

import java.io.PrintWriter;
import java.util.Scanner;
/**
 * 
 * @author shivendra
 * Min Edit Distance (Levenshtein) 
 */
public class DP_1207 {
	
	public static void main(String[] args) {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner scn = new Scanner(System.in);
		
		String x = //"10 AGTCTGACGC";
               null;
		while(scn.hasNextLine() && (x=scn.nextLine())!=null && x.length() >0){
		String y = //"11 AGTAAGTAGGC";
				scn.nextLine();
		
		String[] arr1 = x.split("\\s");
		String[] arr2 = y.split("\\s");
		
		int len1 = Integer.parseInt(arr1[0].trim());
		String str1 = arr1[1];
		while(str1.length()<len1)str1 = str1.concat(" ");
		int len2 = Integer.parseInt(arr2[0].trim());
		String str2 = arr2[1];
		while(str2.length()<len2)str2 = str2.concat(" ");
		
		int[][] table = new int[len1+1][len2+1];
		for(int i=0; i<=len1; i++){
			for(int j=0; j<=len2; j++){
				if(i==0 && j==0)table[i][j] = 0;
				else if(i==0){
					table[i][j] = table[i][j-1] -1;
				}
				else if(j==0){
					table[i][j] = table[i-1][j] -1;
				}else{
					int match_mismatch = table[i-1][j-1] +(str1.charAt(i-1) == str2.charAt(j-1)? 0: -1 );
					int insert = table[i-1][j] -1;
					int del = table[i][j-1] -1;
					table[i][j] = Math.max(match_mismatch, Math.max(insert, del));
				}
				
			}
		}
		
		pw.println(table[len1][len2]<0?-table[len1][len2]: table[len1][len2]);
		}
		pw.close();
	}

}
